import java.util.*;
import java.io.*;
import org.apache.commons.lang3.StringUtils;

class StudentCourse {
		private String strStUId;
		private List<String> crsesRegd;
		private List<String> crseGrades;
		private int nCoursesRegd;

		StudentCourse(String strId) {
			strStUId = strId;
			crsesRegd = new ArrayList<String>();
			crseGrades = new ArrayList<String>();
			nCoursesRegd = 0;
		}

		public List<String> getRegCourses() {
			return crsesRegd;
		}
		// to be used only at the time of database read / write..
		public void AddCourseAndGrade(String strCrseId, String strGrade) {
			crsesRegd.add(strCrseId);
			crseGrades.add(strGrade);
			nCoursesRegd++;
		}

		public String getStudentId() {
			return strStUId;
		}

		public boolean isStudentRegdForCourse(String strCrseId) {
			if (nCoursesRegd == 0)
				return false;

			for (int n = 0; n < nCoursesRegd ; n++) {
				String str = crsesRegd.get(n);
				if (StringUtils.equals(str, strCrseId))
					return true;
			}

			return false;
		}

		public boolean RegisterCourseToStudent(String strCrseId) {
			if (this.isStudentRegdForCourse(strCrseId))
				return false;

			crsesRegd.add(strCrseId);
			crseGrades.add("-");

			nCoursesRegd++;
			return true;
		}

		public boolean DropACourseForStudent(String strCrseId) {
			if (!(this.isStudentRegdForCourse(strCrseId)))
				return false;

			//crsesRegd.remove(strCrseId);
			//crseGrades.remove(

			for (int n = 0; n < nCoursesRegd ; n++) {
				if (StringUtils.equals(strCrseId, crsesRegd.get(n))) {
					crsesRegd.remove(n);
					crseGrades.remove(n);
					nCoursesRegd--;
					return true;
				}
			}
			return false;
		}

		public boolean AssignGradeForCourse(String strCrseId, String strGrade) {
			if (!(this.isStudentRegdForCourse(strCrseId)))
				return false;

			for (int n = 0; n < nCoursesRegd ; n++) {
				String str = crsesRegd.get(n);
				if (StringUtils.equals(str, strCrseId)) {
					crseGrades.set(n, strGrade);
					return true;
				}
			}

			return false;
		}

		public int NumberOfCoursesRegistered() {
			return nCoursesRegd;
		}

		public String GetGradeForCourse(String strCrseId) {
			if (this.isStudentRegdForCourse(strCrseId))
				return null;

			for (int n = 0; n < nCoursesRegd ; n++) {
				String str = crsesRegd.get(n);
				if (StringUtils.equals(str, strCrseId)) {
					return crseGrades.get(n);
				}
			}

			return null;
		}

		public String toString() {
				String str = new String(strStUId);
				str += "," ;
				str += Integer.toString(nCoursesRegd);
				str += "," ;
				for (int n = 0; n < nCoursesRegd ; n++) {
					str += crsesRegd.get(n);
					str += ",";
					str += crseGrades.get(n);
					if (n != nCoursesRegd-1)
						str += ",";
				}

				return str;
		}
}
